• Jump To … +
    main.js separate.js single.js web-apg-api.js main.js web-conv-api.js ast.js csv.js dangling-else.js display.js flags.js float.js limits.js main.js multiline-mode.js recursive.js replace.js rules.js split.js testonly.js trace.js udt.js unicode.js web-email.js word-boundaries.js main.js phone-number.js web-main.js web-phone-number.js main.js phone-number.js setup.js translate.js xml.js branch-fail-grammar.js main.js parent-mode-grammar.js setup.js universal-mode-grammar.js colors-app.js colors-callbacks.js colors.js main.js more-app.js more-setup.js more.js ast-callbacks.js bad-input.js basic.js ini-file.js main.js parser-callbacks.js setup.js trace.js anbncn.js and.js c-comment.js compound.js main.js nested.js not.js setup.js boundaries-grammar.js boundaries.js comment-grammar.js comment.js main.js negative-grammar.js negative.js positive-grammar.js positive.js setup.js main.js odata-grammar.js run.js setup.js area-code.js lookaround.js main.js phone-number.js setup.js simple.js all-operators.js default.js fancy-number.js limited-lines.js main.js select-operators.js select-rules.js setup.js main.js minimal.js parent-u.js parent.js phone-number.js setup.js stats.js trace.js universal-u.js universal.js callbacks.js grammar.js main.js parser.js writeHtml.js LICENSE.md README.md index.md
  • phone-number.js

  • §

    copyright: Copyright (c) 2024 Lowell D. Thomas, all rights reserved
    license: BSD-2-Clause (https://opensource.org/licenses/BSD-2-Clause)

    Generated by apg-js, Version 4.4.0 apg-js

    module.exports = function grammar(){
  • §
    SUMMARY
         rules = 7
          udts = 0
       opcodes = 20
           ---   ABNF original opcodes
           ALT = 0
           CAT = 3
           REP = 2
           RNM = 9
           TLS = 3
           TBS = 0
           TRG = 3
           ---   SABNF superset opcodes
           UDT = 0
           AND = 0
           NOT = 0
           BKA = 0
           BKN = 0
           BKR = 0
           ABG = 0
           AEN = 0
    characters = [40 - 57]
    
      /* OBJECT IDENTIFIER (for internal parser use) */
      this.grammarObject = 'grammarObject';
    
      /* RULES */
      this.rules = [];
      this.rules[0] = { name: 'phone-number', lower: 'phone-number', index: 0, isBkr: false };
      this.rules[1] = { name: 'area-code', lower: 'area-code', index: 1, isBkr: false };
      this.rules[2] = { name: 'office', lower: 'office', index: 2, isBkr: false };
      this.rules[3] = { name: 'subscriber', lower: 'subscriber', index: 3, isBkr: false };
      this.rules[4] = { name: 'gt-2', lower: 'gt-2', index: 4, isBkr: false };
      this.rules[5] = { name: 'not-9', lower: 'not-9', index: 5, isBkr: false };
      this.rules[6] = { name: 'digit', lower: 'digit', index: 6, isBkr: false };
    
      /* UDTS */
      this.udts = [];
    
      /* OPCODES */
      /* phone-number */
      this.rules[0].opcodes = [];
      this.rules[0].opcodes[0] = { type: 2, children: [1,2,3,4,5,6] };// CAT
      this.rules[0].opcodes[1] = { type: 7, string: [40] };// TLS
      this.rules[0].opcodes[2] = { type: 4, index: 1 };// RNM(area-code)
      this.rules[0].opcodes[3] = { type: 7, string: [41] };// TLS
      this.rules[0].opcodes[4] = { type: 4, index: 2 };// RNM(office)
      this.rules[0].opcodes[5] = { type: 7, string: [45] };// TLS
      this.rules[0].opcodes[6] = { type: 4, index: 3 };// RNM(subscriber)
    
      /* area-code */
      this.rules[1].opcodes = [];
      this.rules[1].opcodes[0] = { type: 2, children: [1,2,3] };// CAT
      this.rules[1].opcodes[1] = { type: 4, index: 4 };// RNM(gt-2)
      this.rules[1].opcodes[2] = { type: 4, index: 5 };// RNM(not-9)
      this.rules[1].opcodes[3] = { type: 4, index: 6 };// RNM(digit)
    
      /* office */
      this.rules[2].opcodes = [];
      this.rules[2].opcodes[0] = { type: 2, children: [1,2] };// CAT
      this.rules[2].opcodes[1] = { type: 4, index: 4 };// RNM(gt-2)
      this.rules[2].opcodes[2] = { type: 3, min: 2, max: 2 };// REP
      this.rules[2].opcodes[3] = { type: 4, index: 6 };// RNM(digit)
    
      /* subscriber */
      this.rules[3].opcodes = [];
      this.rules[3].opcodes[0] = { type: 3, min: 4, max: 4 };// REP
      this.rules[3].opcodes[1] = { type: 4, index: 6 };// RNM(digit)
    
      /* gt-2 */
      this.rules[4].opcodes = [];
      this.rules[4].opcodes[0] = { type: 5, min: 50, max: 57 };// TRG
    
      /* not-9 */
      this.rules[5].opcodes = [];
      this.rules[5].opcodes[0] = { type: 5, min: 48, max: 56 };// TRG
    
      /* digit */
      this.rules[6].opcodes = [];
      this.rules[6].opcodes[0] = { type: 5, min: 48, max: 57 };// TRG
  • §

    The toString() function will display the original grammar file(s) that produced these opcodes.

      this.toString = function toString(){
        let str = "";
        str += ";\n";
        str += "; Ref: Wikipedia, North American Numbering Plan\n";
        str += ";\n";
        str += "phone-number = \"(\" area-code \")\" office \"-\" subscriber\n";
        str += "area-code = gt-2 not-9 digit\n";
        str += "office = gt-2 2digit\n";
        str += "subscriber = 4digit\n";
        str += "gt-2 = %d50-57\n";
        str += "not-9 = %d48-56\n";
        str += "digit = %d48-57\n";
        return str;
      }
    }